/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUIUtilities;

import java.util.Comparator;
import java.util.Vector;
import multiarray.MultiArray;

/**
 *
 * @author Evan
 */
public class IntVectorComparator implements Comparator<Vector<Integer>>
{

  public enum ComparatorSettings
  {

    population, power
  };
  ComparatorSettings setting = ComparatorSettings.population;
  private MultiArray<Integer> pop = null;
  private MultiArray<Double> power = null;

  public IntVectorComparator(MultiArray<Integer> pop)
  {
    this.pop = pop;
  }

  public IntVectorComparator(MultiArray<Integer> pop, MultiArray<Double> power)
  {
    this.pop = pop;
    this.power = power;
  }

  public void setComparitor(ComparatorSettings setting)
  {
    this.setting = setting;
  }

  public int compare(Vector<Integer> a, Vector<Integer> b)
  {
    double aValue = pop.getElementAtIndex(convertVectorToArray(a));
    double bValue = pop.getElementAtIndex(convertVectorToArray(b));

    if (setting == ComparatorSettings.power)
    {
      aValue *= power.getElementAtIndex(convertVectorToArray(a));
      bValue *= power.getElementAtIndex(convertVectorToArray(b));
    }

    if (aValue < bValue)
    {
      return -1;
    }
    else if (aValue > bValue)
    {
      return 1;
    }
    else
    {
      return 0;
    }
  }

  private int[] convertVectorToArray(Vector<Integer> v)
  {
    int[] ret = new int[v.size()];

    for (int i = 0; i < v.size(); i++)
    {
      ret[i] = v.get(i);
    }

    return ret;
  }
}
